public class Solution55 {
    public boolean canJump(int[] nums) {
        if (nums.length==1){
            return true;
        }
        int l=0;
        while (nums[l]!=0){
            int target=-1,pos=-1;
            for (int i=1;i<=nums[l];i++){
                if (l+i>=nums.length-1 || l+i+nums[l+i]>=nums.length-1){
                    return true;
                }
                if (l+i+nums[l+i]>target){
                    target=l+i+nums[l+i];
                    pos=l+i;
                }
            }
            l=pos;
        }
        return false;
    }

    public static void main(String[] args) {
        System.out.println(new Solution55().canJump(new int[]{2,0}));
    }
}
